package com.zzptc.zzsgz.bdsjws.activities;

import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.fragments.UpdateVersionFragment;
import com.zzptc.zzsgz.bdsjws.vo.VersionInfo;

import butterknife.OnClick;

public class UpdateActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public int getContentXML() {
        return R.layout.activity_update;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {

    }

    @OnClick(R.id.textView2)
    public void onViewClicked() {
       // startActivity(new Intent(this,CheckUpdateActivity.class));
        startActivityForResult(new Intent(this,CheckUpdateActivity.class),0);
    }

    public void showDialog(String msg){
        FragmentManager fm1=getFragmentManager();
        UpdateVersionFragment u1= UpdateVersionFragment.getUpdateVersionFragment(msg);
        //终于让对话框出现了
        u1.show(fm1,"");
    }
    //接收(第二个参数就是传过来的值)

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (resultCode){
            case 2:
                Toast.makeText(this, "网络断了，请检查网络。。。", Toast.LENGTH_SHORT).show();
                showDialog( "网络断了，请检查网络。。。");
                break;
            case 1:
                Toast.makeText(this, "有网络，但比较慢。。。", Toast.LENGTH_SHORT).show();
                showDialog("有网络，但比较慢。。。");
                break;
            case 3:
                VersionInfo versionInfo= (VersionInfo) data.getSerializableExtra("VersionInfo");
                //接收(第二个参数和第三个参数就是传过来的值) 只有3带过来两个参数，其它都只带一个参数
                String apkrul=versionInfo.getApkurl();
               Toast.makeText(this, versionInfo.getApkurl()+"", Toast.LENGTH_SHORT).show();
             //   Toast.makeText(this, "网络正常，可以下载。。。", Toast.LENGTH_SHORT).show();
               FragmentManager fm=getFragmentManager();
               UpdateVersionFragment u= UpdateVersionFragment.getUpdateVersionFragment(versionInfo);
               //终于让对话框出现了
                u.show(fm,"");
                break;
            case 4:

                Toast.makeText(this, "网络正常，已经是最新版本。。。", Toast.LENGTH_SHORT).show();
              showDialog("网络正常，已经是最新版本。。。");
                break;
        }
    }
}
